<template>
  <div class="index-layout">
    <!--内部内容-->
    <transition name="index">
      <router-view></router-view>
    </transition>
  </div>
</template>
<script>
  import { mapState } from 'vuex'
  import setTitle from '../../../utils/setTitle'
  export default {
    computed: mapState(['indexTitle', 'indexRouterData']),
    mounted () {
      this.onReady()
      this.routerChange()
    },
    methods: {
      onReady () {
        let path = this.$route.path.replace('/', '')
        this.$store.dispatch('setIndexTitle', setTitle.indexTitle(path, this.indexRouterData))
      },
      routerChange () {
        this.$router.beforeEach((to, from, next) => {
          let path = to.path.replace('/', '')
          this.$store.dispatch('setIndexTitle', setTitle.indexTitle(path, this.indexRouterData))
          next()
        })
      }
    }
  }
</script>
